<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
            .ui-commandButton-wizard-selected{
                background-color: #D20005;
                font-weight: bold;
                color: #000000;
            }
            .ui-commandButton-wizard-unselected{
                background-color: #D20005;
                font-weight: bold;
                color: #AFAFAF;
            }
        </style>
        <h2>View Sales Invoice</h2>
        <h:form id="salesInvoice" style="font-size: 85%">
            <br/>
            <p:panel id="invoice1">

                <br/>
                <br/>
                <h:panelGrid columns="2" style="width: 100%" >

                    <h:panelGrid columns="1" style="border-style: solid; border-width: thin; width: 100%" >
                        <h:panelGrid columns="2" cellpadding="10" style="width: 100%">
                            <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                            <h:outputText id="clientId" value="#{sbpInvoiceManagerBean.invoice.customer.clientId}"/>
                            <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                            <h:outputText id="companyName" value="#{sbpInvoiceManagerBean.invoice.customer.companyName}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>
                        </h:panelGrid>
                        <h:panelGrid columns="1" style="width: 100%; padding: 0px 10px">
                            <h:outputText value="Billing Address" style="font-weight: bold; font-size: 110%"/>
                            <p:separator/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.customer.billingAddress.addressLine1}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.addressLine2}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.city}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.stateName}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.country}" />
                            <h:outputText value="#{salesOrdersbpInvoiceManagerBean.invoice.customer.billingAddress.zipCode}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>

                            <h:outputText value="Shipping Address" style="font-weight: bold; font-size: 110%"/>
                            <p:separator/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.addressLine1}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.addressLine2}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.city}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.stateName}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.country}" />
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.shippingAddress.zipCode}" />
                            <h:outputText value=""/>
                            <h:outputText value=""/>
                        </h:panelGrid>
                    </h:panelGrid>

                    <h:panelGrid columns="4" cellpadding="10" style="width: 100%">
                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Date: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.invoiceDate}" style="text-align: left">
                            <f:convertDateTime pattern="MMMM dd, yyyyy"/>
                        </h:outputText>

                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Invoice Number: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.invoiceId}" />

                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Purchase Order Number: "/>
                        <h:outputText value="#{sbpInvoiceManagerBean.invoice.poNumber}" />

                        <h:outputText value=""/>
                        <h:outputText value=""/>
                        <h:outputLabel style="font-weight: bold" value="Status: "/>
                        <h:selectOneRadio disabled="true" value="#{sbpInvoiceManagerBean.invoice.paid}">
                            <f:selectItem itemLabel="Paid" itemValue="true"/>
                            <f:selectItem itemLabel="Unpaid" itemValue="false"/>
                        </h:selectOneRadio>
                    </h:panelGrid>
                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Delivery Order" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Delivery Order"/> 
                <br/>
                <p:dataTable id="olilTable" var="oneIL" value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.itemLines}" emptyMessage="No products selected">
                    <p:column headerText="Product Type" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.product.productType}"/>
                    </p:column>
                    <p:column headerText="Quantity Ordered Case" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.qtyOrderedCase}"/>
                    </p:column>
                    <p:column headerText="Unit Price (SGD)" rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (soManagerBean.salesOrder.currency)}">
                        <h:outputText value="#{oneIL.unitPriceSGD}" />
                    </p:column>
                    <p:column headerText="Unit Price (USD)" rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (!soManagerBean.salesOrder.currency)}">
                        <h:outputText value="#{oneIL.unitPriceUSD}" />
                    </p:column>
                    <p:column headerText="Order Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.orderDiscount}" />
                    </p:column>
                    <p:column headerText="Special Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.specialDiscount}" />
                    </p:column>
                    <p:column headerText="Sub-total" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.subTotal}">
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                    </p:column>
                </p:dataTable>
                <br/>

                <br/>
                <br/>
                <p:separator style="height:1px; border-color: #000000; color: #000000; background-color: #000000; outline-color: #000000"/> 
                <div align="right">
                    <h3>
                        <h:panelGrid columns ="2" cellpadding="2" style="text-align: right">
                            <h:outputLabel style="font-weight: bold" value="Sub-total: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.subtotal}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Order Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.orderDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Member Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.memberDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Special Discount: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.deliveryOrder.specialDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Tax: "/>
                            <h:outputText value="#{sbpInvoiceManagerBean.invoice.tax}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h3>
                    <h2>
                        <h:panelGrid columns ="2" cellpadding="10">
                            <h:outputLabel for="total" style="font-weight: bold" value="Total: "/>
                            <h:outputText id="total" value="#{sbpInvoiceManagerBean.invoice.total}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h2>
                </div>

            </p:panel>

            <br/>
            <br/>
            <div align="left">
<!--                <h:commandLink value="Invoice to PDF" actionListener="{jrManagerBean.generateSalesInvoiceReport}" target="_blank">
                    <f:attribute name="invoice" value="{sbpInvoiceManagerBean.invoice}"/>
                </h:commandLink>-->
                <p:lightBox iframe="true" width="80%" height="80%">  
                    <h:outputLink value="/merlion-war/CommonUtility/jasperreports">
                        <f:param name="type" value="invoice" /> 
                        <f:param name="strId" value="#{sbpInvoiceManagerBean.invoice.id}" />
                        <h:outputText value="View Invoice PDF" style="font-weight: bold; font-size: 125%"/>
                    </h:outputLink> 
                </p:lightBox>
            </div>
            <div align="right">
                <p:commandButton value="Send Invoice" action="#{sbpInvoiceManagerBean.sendInvoiceToCustomer}"/>
            </div>
            <br/>
            <br/>
        </h:form>


    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>